package main
import (
	"fmt"
	"os"
	"os/exec"
	"bufio"
	)

func runCommand() {
	var (
		err error
	)

	cmdName := "docker"
	cmdArgs := []string{"build","--no-cache=true"}
	
	cmd := exec.Command(cmdName,cmdArgs...)

	cmdReader, err := cmd.StdoutPipe()
	if err != nil {
		fmt.Println(os.Stderr,"Error creating StdoutPipe for Cmd",err)
	}

	scanner := bufio.NewScanner(cmdReader)
	go func() {
		for scanner.Scan() {
			fmt.Printf("docker build out | %s\n",scanner.Text());
		}
	}()

	err = cmd.Start()
	if err != nil {
		fmt.Println(os.Stderr,"Error starting Cmd",err)
	}

	err = cmd.Wait()
	if err != nil {
		fmt.Println(os.Stderr,"Error waiting for cmd",err)
	}
}

func main() {
	runCommand()
}
